package com.example.feign;

import com.alibaba.fastjson.JSONObject;
import com.example.auth.domain.DataNode;
import com.example.auth.domain.User;
import com.example.util.MethodDesc;
import com.example.util.Module;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

@Module(name = "认证服务模块", description = "查询用户及用户所属数据节点获取")
@FeignClient(value = "cloud-auth",fallback = com.example.feign.impl.UserFeignServiceImpl.class)
public interface UserFeignService {

    @MethodDesc(description = "根据用户名查找用户")
    @GetMapping("/user/search")
    public User getUserByUserName(@RequestParam("username")String username);

    @MethodDesc(description = "根据用户名查找用户")
    @GetMapping("/user/search/hash")
    public User getUserByHashUserName(@RequestParam("username")String username);

    @MethodDesc(description = "根据用户id查找用户")
    @GetMapping("/user/search/userId")
    public User getUserByUserId(@RequestParam("userId")String userId);

    @MethodDesc(description = "根据用户id查找用户")
    @GetMapping("/user/search/userId/hash")
    public User getUserByHashUserId(@RequestParam("userId")String userId);

    @MethodDesc(description = "注册用户")
    @PostMapping("/user/registerUser")
    public JSONObject registerUser(@RequestBody JSONObject jsonObject);

    @MethodDesc(description = "注册用户通过hash取模分表")
    @PostMapping("/user/registerUserHash")
    public JSONObject registerUserHash(@RequestBody JSONObject jsonObject);

    @MethodDesc(description = "根据用户名，查找储存用户数据节点")
    @GetMapping("/user/dataNodeByUserName")
    DataNode findNodeByUsername(@RequestParam("username") String username);

    @MethodDesc(description = "根据用户id，查找储存用户数据节点")
    @GetMapping("/user/dataNodeByUserId")
    DataNode findNodeByUserId(@RequestParam("userId") String userId);


    @MethodDesc(description = "获取用户总条数")
    @GetMapping("/user/total/hash")
    Integer findUserTotalHash();


    @MethodDesc(description = "获取用户数分页")
    @GetMapping("/user/page")
    JSONObject getPageList(@RequestParam("pageNum")Integer pageNum,@RequestParam("pageSize")Integer pageSize,@RequestParam("userName")String userName);


    @MethodDesc(description = "修改用户数密码")
    @PostMapping("/user/updatepwd")
    JSONObject updatePassword(@RequestBody JSONObject jsonObject);

    @MethodDesc(description = "删除用户")
    @GetMapping("/user/delete/userId")
    JSONObject deleteUser(@RequestParam("userId")String userId);

    @MethodDesc(description = "获取用户服务名")
    @GetMapping("/user/getusernode")
    DataNode getUserNodeByNodeNo(@RequestParam("userName")String userName,@RequestParam("nodeNo")String nodeNo);

    @MethodDesc(description = "获取用户服务名通过用户id")
    @GetMapping("/user/getusernode/userId")
    DataNode getUserNodeByNodeNoUserId(@RequestParam("userId")String userId,@RequestParam("nodeNo")String nodeNo);

}
